﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IBupro.Models.Classes;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using iBuproModel.Repositories.Interfaces;
using iBuproModel;

namespace IBupro.Models
{
    public class StudentProjectModel : CustomModel
    {
        [Required(ErrorMessage = "*")]
            
        public string Name { get; set; }

        [Required(ErrorMessage = "*")]
        public string Detail { get; set; }

        [Required(ErrorMessage = "*")]
        public int SubjectId { get; set; }

        [Required(ErrorMessage = "*")]
        public int MemberCount { get; set; }

        [Required(ErrorMessage = "*")]
        public string ShortCut { get; set; }

        [Required(ErrorMessage = "*")]
        public bool Locked { get; set; }

        [Required(ErrorMessage = "*")]
        public string Tags { get; set; }


        public SelectList GetSubjectList()
        {
            ISubjectRepository subjects = repositoryService.SubjectRepositoryCreateInstace();
            return new SelectList(subjects.GetAll(), "Id", "Name");
        }

        public Project ModelToProject(User projectFounder)
        {
            ISubjectRepository subjects = repositoryService.SubjectRepositoryCreateInstace();
            ITagRepository tags = repositoryService.TagRepositoryCreateInstance();
            Project project = new Project();

            project.Name = this.Name;
            project.Principal = projectFounder;
            project.Detail = this.Detail;
            project.Subject = subjects.First(s => s.Id == this.SubjectId);
            project.MemberCount = this.MemberCount;
            project.Created = DateTime.Now;
            project.Shortcut = this.ShortCut;
            project.Locked = this.Locked;
            tags.SaveTagsForProject(this.Tags,project);

            return project;
        }
    }
}